/*
 * @lc app=leetcode.cn id=108 lang=javascript
 *
 * [108] 将有序数组转换为二叉搜索树
 */

// @lc code=start
/**
 * Definition for a binary tree node.
 * function TreeNode(val, left, right) {
 *     this.val = (val===undefined ? 0 : val)
 *     this.left = (left===undefined ? null : left)
 *     this.right = (right===undefined ? null : right)
 * }
 */
/**
 * @param {number[]} nums
 * @return {TreeNode}
 */
var sortedArrayToBST = function(nums) {
    if (!nums.length) {
        return undefined
    }
    let half = Math.floor(nums.length / 2)
    let leftBTS = sortedArrayToBST(nums.slice(0, half))
    let rightBTS = sortedArrayToBST(nums.slice(half + 1, nums.length))
    return new TreeNode(nums[half], leftBTS, rightBTS)
};
// @lc code=end

